﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Datos;
using Clases;

namespace Trade
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            datOrdenCompra Orden = new datOrdenCompra();
            datEmpresa datEmp = new datEmpresa();
            dtg_Proveedores.DataSource = Orden.ConsultarProveedor(Convert.ToDecimal(Session["Id_Empresa"]));
            dtg_Proveedores.DataBind();

            if (!IsPostBack)
            {
                string var = Convert.ToString(Request.QueryString["prov"]);
                if (var != null)
                {

                    String[] Datos = var.Split('?');
                    string cod_proveedor = Datos[0].ToString();
                    Session["Cod_Proveedor"] = cod_proveedor;
                    Decimal empresa_ = Convert.ToDecimal(Session["Id_Empresa"]);

                    if (datEmp.GuardarProveedor(empresa_, Convert.ToDecimal(cod_proveedor)))
                    {
                        lblAddExito.Visible = true;
                    }
                    else
                    {
                        lblAddExito.Text = "Error";
                        lblAddExito.Visible = true;
                    }
                    Response.Redirect("CProveedor.aspx", true);

                }
            }
        }



        protected void btnAdd_Click(object sender, EventArgs e)
        {
            datEmpresa datEmp = new datEmpresa();
            dtgProveedores.DataSource = datEmp.ConsultarNoProveedor(Convert.ToDecimal(Session["Id_Empresa"]));
            dtgProveedores.DataBind();
            Popup_Buscar_Proveedor.ShowOnPageLoad = true;
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("Home.aspx", true);
        }
    }
}